package com.hcw.library.controller;

import com.hcw.library.common.Result;
import com.hcw.library.domain.Book;
import com.hcw.library.service.BookService;
import com.hcw.library.vo.BookVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping("/book/addBook")
    @ResponseBody
    public Result<Integer> addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }

    @GetMapping("/book/deleteBook")
    @ResponseBody
    public Result<Integer> deleteBook(String id){
        return bookService.deleteBook(id);
    }

    @PostMapping("/book/updateBook")
    @ResponseBody
    public Result<Integer> updateBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }

    @GetMapping("/book/queryBookList")
    @ResponseBody
    public Result<List<BookVO>> queryBookList(Integer currentPage){
        return bookService.queryBookList(currentPage);
    }


}
